package handles

import (
	"github.com/form3tech-oss/jwt-go"
	"github.com/gofiber/fiber/v2"
	"go-server/app/dto"
	"go-server/app/models"
	"go-server/kit"
)

type User struct {
}

// UserInfo 获取用户信息
func (User) UserInfo(ctx *fiber.Ctx) error {
	user := ctx.Locals("user").(*jwt.Token)
	claims := user.Claims.(jwt.MapClaims)
	name := claims["name"].(string)
	model := models.Account{}
	model.Username = name
	table, _ := model.GetUser()
	res := dto.UserInfoRes{Username: table.Username, NickName: table.NickName,
		Phone: table.Phone, Email: table.Email, Avatar: table.Avatar}
	return ctx.Status(fiber.StatusOK).JSON(kit.OkAndData(res))

}
